<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <ui:composition template="/faces/templates/master_nonav.xhtml">
        <ui:define name="content">
            <h:form id="frm_pcr">
                <f:event type="preRenderView" listener="#{puCRViewBean.preRenderListenenr()}"/>
                <p:fieldset id="fs_owncr" legend="#{msg.classroom_home_fs_owncr_legend}">
                    <h:outputText id="lbl_owncr_new_value1" value="#{msg.classroom_home_lbl_owncr_new_value1}" rendered="#{puCRViewBean.maxOwnClassRoomReached()}"/>
                    <h:outputText id="lbl_owncr_new_value2" value="#{msg.classroom_home_lbl_owncr_new_value2}" rendered="#{!puCRViewBean.maxOwnClassRoomReached()}"/>
                    <p:commandButton id="btn_owncr_new" value="#{msg.btn_new}" onclick="dlgOwnPCRNew.show()" rendered="#{!puCRViewBean.maxOwnClassRoomReached()}"/>
                    <p:separator/>
                    <p:dataGrid id="tbl_owncr" columns="2" var="ownPCR" value="#{puCRViewBean.ownPublicCRDataModel}" emptyMessage="#{msg.classroom_home_tbl_owncr_empty}">
                        <p:panel id="pnl_owncr" header="#{ownPCR.title}" styleClass="noborder">
                            <p:panelGrid id="tbl_pnl_owncr_info" columns="2" styleClass="noborder">
                                <h:outputText id="lbl_pnl_owncr_1" value="#{msg.classroom_home_lbl_pnl_owncr_1}"/>
                                <h:outputText id="lbl_pnl_owncr_cntUser" value="#{puCRViewBean.cntOwnPCRUser()}"/>
                                <h:outputText id="lbl_pnl_owncr_2" value="#{msg.classroom_home_lbl_pnl_owncr_2}"/>
                                <h:outputText id="lbl_pnl_owncr_cnt" value="#{puCRViewBean.cntOwnPCRFCB()}"/>
                            </p:panelGrid>
                            <p:separator/>
                            <p:commandButton id="btn_open" value="#{msg.btn_open}" action="#{showClassRoomBean.open(ownPCR)}" ajax="false" immediate="true"/>
                            <p:commandButton id="btn_delete" value="#{msg.btn_delete}" actionListener="#{puCRViewBean.deletePuCR()}" update=":frm_pcr" rendered="#{puCRViewBean.cntOwnPCRUser() == 1}"/>
                        </p:panel>
                    </p:dataGrid>
                </p:fieldset>
                <p:separator id="sep" rendered="#{puCRViewBean.hasInvitations()}"/>
                <p:fieldset id="fs_invcr" legend="#{msg.classroom_home_fs_invcr_legend}" rendered="#{puCRViewBean.hasInvitations()}">
                    <p:dataTable id="tbl_invcr" rowIndexVar="row" var="p" value="#{puCRViewBean.invitations}"
                                 emptyMessage="#{classroom_home_tbl_invcr_empty}" rowKey="#{p.id}">
                        <p:column>
                            #{row +1}
                        </p:column>
                        <p:column>
                            #{p.publicClassRoom.title}
                        </p:column>
                        <p:column>
                            #{p.publicClassRoom.owner.firstname} #{p.publicClassRoom.owner.lastname}
                        </p:column>
                        <p:column>
                            #{p.classRoomRole}
                        </p:column>
                        <p:column>
                            <p:commandButton id="btn_accept" value="#{msg.btn_accept}" actionListener="#{puCRViewBean.acceptInvitation}" update="@form" process="@form"/>
                            <h:outputText value=" "/>
                            <p:commandButton id="btn_reject" value="#{msg.btn_reject}" actionListener="#{puCRViewBean.rejectInvitation}" update="@form" process="@form"/>
                        </p:column>
                    </p:dataTable>
                </p:fieldset>
                <p:separator/>
                <p:fieldset id="fs_forcr" legend="#{msg.classroom_home_fs_forcr_legend}">
                    <p:dataGrid id="tbl_forcr" columns="2" var="forPCR" value="#{puCRViewBean.foreignPublicCRDataModel}" emptyMessage="#{msg.classroom_home_tbl_forcr_empty}">
                        <p:panel id="pnl_forcr" header="#{forPCR.title}" styleClass="noborder">
                            <p:panelGrid id="tbl_pnl_forcr_info" columns="2" styleClass="noborder">
                                <h:outputText id="lbl_pnl_forcr_1" value="#{msg.classroom_home_lbl_pnl_owncr_1}"/>
                                <h:outputText id="lbl_pnl_forcr_cntUser" value="#{forPCR.participants.size() + 1}"/>
                                <h:outputText id="lbl_pnl_forcr_2" value="#{msg.classroom_home_lbl_pnl_owncr_2}"/>
                                <h:outputText id="lbl_pnl_forcr_cnt" value="#{forPCR.fileCardBoxes.size()}"/>
                            </p:panelGrid>
                            <p:separator/>
                            <p:commandButton id="btn_open" value="#{msg.btn_open}" action="#{showClassRoomBean.open(forPCR)}" ajax="false" immediate="true"/>
                            <p:commandButton id="btn_leave" value="#{msg.btn_leave}" actionListener="#{puCRViewBean.leavePuCR}" update=":frm_pcr"/>
                        </p:panel>
                    </p:dataGrid>
                </p:fieldset>
            </h:form>
            <p:dialog id="dlg_ownpcrnew" header="#{msg.classroom_home_dlg_ownpcrnew_header}" widgetVar="dlgOwnPCRNew" modal="true">
                <p:ajax event="close" update=":frm_pcr" listener="#{puCRViewBean.cancelNewOwnPCR()}" oncomplete="dlgOwnPCRNew.hide()" immediate="true"/>
                <h:form>
                    <p:panel>
                        <p:panelGrid id="tbl_dlg_ownpcrnew" columns="3" styleClass="noborder">
                            <p:outputLabel id="lbl_dlg_ownpcrnew_title" for="txt_dlg_ownpcrnew_title" value="#{msg.classroom_home_lbl_dlg_ownpcrnew_title_value}"/>
                            <p:inputText id="txt_dlg_ownpcrnew_title" value="#{puCRViewBean.newPuCR.title}" required="true" requiredMessage="#{msg.classroom_home_txt_dlg_ownpcrnew_title_reqMes}"/>
                            <p:message for="txt_dlg_ownpcrnew_title" showDetail="true"/>
                        </p:panelGrid> 
                        <f:facet name="footer">
                            <p:commandButton id="btn_owncr_save" value="#{msg.btn_save}" actionListener="#{puCRViewBean.saveNewOwnPCR()}" oncomplete="handleSaveRequest(xhr, status, args)" update=":frm_pcr"/>
                            <p:commandButton id="btn_owncr_cancel" value="#{msg.btn_cancel}" actionListener="#{puCRViewBean.cancelNewOwnPCR()}" oncomplete="dlgOwnPCRNew.hide()"  update=":frm_pcr" immediate="true"/> 
                        </f:facet>
                    </p:panel>
                </h:form>
            </p:dialog>
            <script type="text/javascript">  
                function handleSaveRequest(xhr, status, args) {  
                    if(args.validationFailed) {  
                        jQuery('#dlg_ownpcrnew').effect("shake", { times:3 }, 100);  
                    } else {  
                        dlgOwnPCRNew.hide();  
                        jQuery('#btn_owncr_new').fadeOut();  
                    }  
                }  
            </script> 
        </ui:define>
    </ui:composition>
</html>